const APIClient = require('./request.class');

const Model = {
    async getIndex() {
        const Api = new APIClient({
            url: '/',
            method: 'GET'
        })
        try {
            return res = await Api.html();
        } catch (err) {
            this.handleError(err);
        }
    },

    async getList() {
        const Api = new APIClient({
            url: '/list',
            method: 'GET'
        })
        try {
            return res = await Api.html();
        } catch (err) {
            this.handleError(err);
        }
    },

    async getLogin() {
        const Api = new APIClient({
            url: '/login',
            method: 'GET'
        })
        try {
            return res = await Api.html();
        } catch (err) {
            this.handleError(err);
        }
    },

    async getSwagger() {
        const Api = new APIClient({
            url: 'https://api.pjpiao.com/swagger-ui.html',
            method: 'GET'
        })
        try {
            return res = await Api.html();
        } catch (err) {
            this.handleError(err);
        }
    },

    async getHealthy() {
        const Api = new APIClient({
            url: 'https://api.pjpiao.com/api/common/healthy',
            method: 'GET'
        })
        try {
            return res = await Api.reqText();
        } catch (err) {
            this.handleError(err);
        }
    },

    /**
     * 请求错误后提示
     * @param {Object} error
     */
     handleError(error) {
        console.log(error);
    },
};

module.exports = Model;